package cn.itsource.basic.utli;

import cn.itsource.basic.base.domain.ShopReject;
import cn.itsource.org.domain.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;

import javax.mail.internet.MimeMessage;
import java.io.File;

@Component
public class EmailUtil {
    @Autowired
    private JavaMailSender javaMailSender;
    public void SendEmail(Employee employee,ShopReject reject) throws Exception {
        //创建邮件对象
        MimeMessage message = javaMailSender.createMimeMessage();
        //发送邮件复杂工具类
        MimeMessageHelper helper = new MimeMessageHelper(message, true, "utf-8");
        //发件人
        helper.setFrom("1014792931@qq.com");
        helper.setTo(employee.getEmail());
        if(reject.getState()==1){
            //标题
            helper.setSubject("加v看美羊羊洗澡");
            //内容
            helper.setText("<div>\n" +
                    "      <span>审核通过，请点击下方链接激活账号</span>\n" +
                    "      <a href='http://127.0.0.1:8081/#/login'>激活账号</a>\n" +
                    "    </div>",true);
        }else{
            helper.setSubject("注册失败");
            //内容
            helper.setText("<div>\n" +
                    "      <span>"+reject.getReason()+reject.getDesc()+"</span>\n" +
                    "      <a href='http://127.0.0.1:8081/#/rejectReg?id="+reject.getId()+"'>重新修改数据</a>\n" +
                    "    </div>",true);
        }
        System.out.println( "<a href='http://localhost:8081/#/rejectReg?id="+reject.getId()+"'>");
        helper.addAttachment("看看.rar",new File("C:\\Users\\hp\\Desktop\\123\\3458274885714944.zip"));
        javaMailSender.send(message);
    }
}
